<?php
/**
 * 菜单模型
 * @author GL
 * @date 2018.8.27
 */

namespace App\Model\Crm;

use App\model\BaseModel;
use DB;

class MenuModel extends BaseModel{

    const MENU = 'menu';
    const MENU_AUTH = 'menu_access';

    //获取菜单
    public static function menuList($where = [], $field = '*')
    {
        $menu_id = DB::table(self::MENU_AUTH)->where($where)->value('menu_id');
        if($menu_id == 0){
            $menuWhere['status'] = 0;
            $menu = DB::table(self::MENU)->where($menuWhere)->select($field)->get();
        }else{
            $menu_ids = explode(',', trim($menu_id, ','));
            $menu = DB::table(self::MENU)->where('status', 0)->whereIn('id',$menu_ids)->select($field)->get();
        }

        return $menu;
    }
}